package security_strategy

import (
	"app/app_src/framework/ioc"
	"strings"

	"github.com/gin-gonic/gin"
)

// 初始 CurrentSubject 的函数
type InitCurrentSubject func(*gin.Context)

const IOC_KEY_INIT_CURRENT_SUBJECT = "security_strategy.InitCurrentSubject"

// 调用 InitCurrentSubject 函数
func CallInitCurrentSubjectFunc(ctx *gin.Context) {
	initFunc := ioc.Get[InitCurrentSubject](IOC_KEY_INIT_CURRENT_SUBJECT)

	if initFunc == nil {
		msg := strings.Join([]string{`ioc not exists "`, IOC_KEY_INIT_CURRENT_SUBJECT, `"`}, "")
		panic(msg)
	}

	initFunc(ctx)
}
